package edu.zhuoxun.blogserver.map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.zhuoxun.blogserver.entity.Role;
import edu.zhuoxun.blogserver.entity.RolePermissions;
import edu.zhuoxun.blogserver.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.* from user_role ur left join role r on ur.role_id = r.id where ur.user_id = #{id}")
    List<Role> getUserRole(User user);
    @Delete("delete from role_permission where role_id = #{id}")
    void deleteHasPermissions(Role role);
    @Insert("<script> insert into role_permission values " +
            "<foreach collection='hasPermissions' item='permission' index='index' separator=','>" +
            "(#{role.id},#{permission.id})" +
            "</foreach>" +
            "</script>")
    void insertHasPermissions(RolePermissions rolePermissions);
}
